package web.suzy.oj.controller.msg;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.entity.msg.AdminSysNotice;
import web.suzy.oj.pojo.vo.AdminSysNoticeVO;
import web.suzy.oj.service.msg.AdminNoticeService;

import javax.annotation.Resource;

/**
 * YangSuzy 软件工作室
 * 类名: AdminNoticeController
 * 描述: 管理员系统通知控制器
 * 功能: 负责管理员发送系统通知
 *
 * @author YangSuzy
 * Date: 2022/11/18 16:46
 */
@RestController
@RequestMapping("/api/admin/msg")
public class AdminNoticeController {
    @Resource
    private AdminNoticeService adminNoticeService;

    /**
     * 方法名: getSysNotice
     * 描述: 获取系统消息
     *
     * @param limit       每页显示数量
     * @param currentPage 当前页
     * @param type        消息类型
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.AdminSysNoticeVO>>
     * @date 2022/11/18 16:59
     * @auther YangSuzy
     **/
    @GetMapping("/notice")
    @RequiresAuthentication
    @RequiresRoles("root")
    public ResultBean<IPage<AdminSysNoticeVO>> getSysNotice(@RequestParam(value = "limit", required = false) Integer limit,
                                                            @RequestParam(value = "currentPage", required = false) Integer currentPage,
                                                            @RequestParam(value = "type", required = false) String type) {
        return adminNoticeService.getSysNotice(limit, currentPage, type);
    }

    /**
     * 方法名: addSysNotice
     * 描述: 发布系统消息
     *
     * @param adminSysNotice
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/18 16:59
     * @auther YangSuzy
     **/
    @PostMapping("/notice")
    @RequiresAuthentication
    @RequiresRoles("root")
    public ResultBean<Void> addSysNotice(@RequestBody AdminSysNotice adminSysNotice) {
        return adminNoticeService.addSysNotice(adminSysNotice);
    }


    /**
     * 方法名: deleteSysNotice
     * 描述: 删除系统通知
     *
     * @param id 消息ID
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/18 17:07
     * @auther YangSuzy
     **/
    @DeleteMapping("/notice")
    @RequiresAuthentication
    @RequiresRoles("root")
    public ResultBean<Void> deleteSysNotice(@RequestParam("id") Long id) {
        return adminNoticeService.deleteSysNotice(id);
    }

    /**
     * 方法名: updateSysNotice
     * 描述: 更新系统消息
     *
     * @param adminSysNotice 系统消息
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/18 17:12
     * @auther YangSuzy
     **/
    @PutMapping("/notice")
    @RequiresAuthentication
    @RequiresRoles("root")
    public ResultBean<Void> updateSysNotice(@RequestBody AdminSysNotice adminSysNotice) {
        return adminNoticeService.updateSysNotice(adminSysNotice);
    }
}
